<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/4/10
 * Time: 13:54
 */
$client = stream_socket_client('tcp://127.0.0.1:9001');

// 设置非阻塞
stream_set_blocking($client, 0);

$now = time();

fwrite($client, 'hello nonblock');

var_dump(fread($client, 65535));

echo time()-$now;


// stream_select
$read = $write = $except = null;


while (!feof($client)) {
    $read[] = $client;
    var_dump(fread($client , 65535));
    sleep(1);

    // 检查socket 检查情况
    var_dump(stream_select($read, $write, $except, 1));

    foreach ($read as $val) {
        var_dump($val);
    }
}